package com.zhongyu.controller;

import com.zhongyu.pojo.Store;
import com.zhongyu.service.StoreService;
import com.zhongyu.vo.PageResult;
import com.zhongyu.vo.ResultVo;
import com.zhongyu.vo.StoreVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/sys/cangKu/")
public class CangkuController {

    @Resource
    private StoreService storeService;

    @GetMapping("/search/{pageNo}/{pageSize}")
    public ResultVo search(@PathVariable Integer pageNo, @PathVariable Integer pageSize, StoreVo storeVo){
        PageResult pageResult=storeService.searchAll(pageNo,pageSize,storeVo);
        return ResultVo.success(pageResult);

    }
    @GetMapping("/list")
    public ResultVo list(){
        List<Store> list=storeService.searchAll();
        return ResultVo.success(list);
    }

    @PostMapping("/add")
    public ResultVo add(@RequestBody Store store){

        try {
            System.out.println(store);
            storeService.add(store);
            return ResultVo.success("仓库添加成功！");
        }catch (Exception ex){
            return ResultVo.failure("仓库添加失败！",ex);
        }
    }


}
